<%--
  Created by IntelliJ IDEA.
  User: hongfive
  Date: 2019/1/6
  Time: 14:34
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    String path = request.getContextPath();
    String basepath = request.getScheme()
            + "://" + request.getServerName()
            + ":" + request.getServerPort() + "/" + path;
%>
<html>
<head>
    <meta charset="UTF-8">
    <title>油画分类列表</title>
    <link rel="stylesheet" href="<%=basepath%>/statics/backcss/css/index.css">
    <link rel="stylesheet" href="<%=basepath%>/statics/backcss/css/bootstrap.min.css">
    <script src="<%=basepath%>/statics/backcss/js/jquery.min.js"></script>
    <script>
        // 规范时间格式Date()类型
        function formatDate(now) {
            var now = new Date(now);
            var year = now.getFullYear();
            var month = now.getMonth() + 1;
            var date = now.getDate();
            var hour = now.getHours();
            var minute = now.getMinutes();
            var second = now.getSeconds();
            return year + "年" + fixZero(month, 2) + "月" + fixZero(date, 2)
                + "日" + fixZero(hour, 2) + ":" + fixZero(minute, 2) + ":"
                + fixZero(second, 2);
        }
        //时间如果为单位数补0
        function fixZero(num, length) {
            var str = "" + num;
            var len = str.length;
            var s = "";
            for (var i = length; i-->len;) {
                s += "0";
            }
            return s + str;
        }

        function del(cgid) {
            var msg="开始";
            $.ajax({
                url:"../category/Cgdelete",
                dataType:'json',
                data:{
                    cgid: cgid
                },
                async:false,
                type:'post',
                success:function (data) {
                    var json=data;
                    if (json.code==1){
                        msg="删除成功"
                        alter(msg);
                    }
                    else {
                        msg=json.message;
                    }
                },
                error: function(er){
                    alter(er);
                }
            })
        }

        $(function () {
            var re_data = new Object();
            $.ajax({
                url:'../category/Cglist',
                dataType: 'json',
                async:false,
                type:"GET",
                contentType:'application/json;charset=utf-8',
                success: function(data){
                    var json = data;
                    console.log(json);
                    if (json.code == 1){
                        console.log(json.data);
                        re_data = json.data;
                        //展示分类名
                        for (var i=0;i<re_data.length;i++){
                            var com=" <input type=\"hidden\" name=\"cgid\" id=\"cgid\" value=\""+re_data[i].cgid+"\">\n" +
                                "<a href=\"../canvas/index?cgid="+re_data[i].cgid+"\" >"+re_data[i].cgName+"</a>";
                            var dom="<tr>\n" +
                                " <td >"+
                                re_data[i].cgName+"</td>\n" +
                                "<td >" +
                                formatDate(re_data[i].createTime-(14*60*60*1000))+
                                "</td>\n" +
                                "<td >" +
                                formatDate(re_data[i].updateTime-(14*60*60*1000))+
                                "</td>\n" +
                                "<td><a href=\"\">编辑</a></td>\n" +
                                "<td><a onclick='del("+re_data[i].cgid+")' href=\"\">删除</a></td>\n" +
                                "<tr>\n";
                           $("#Cglist").append(dom);
                           $("#Clist").append(com);
                        }
                    }
                    else {
                        re_data=json.message;
                    }
                    console.log(re_data);
                },
                error: function (er) {
                    console.log(er);
                    alert(er)
                }
            })
        })



    </script>
</head>

<body>
<header>
    <div class="container">
        <nav  id="Clist">
        </nav>
        <nav>
            <a href="../category/index" >分类</a>
            <a href="../canvas/listdo">主页</a>
        </nav>
        <nav>
            <a href="#">登录</a>
            <a href="#" onclick="alert('功能暂未开放');">注册</a>
        </nav>
    </div>
</header>
<section class="banner">
    <div class="container">
        <div>
            <h1>油画分类</h1>
            <p>油画分类列表</p>
        </div>
    </div>
</section>
<section class="main">
    <div class="container">
        <table class="table table-striped">
            <thead>
            <tr>
                <th>名称</th>
                <th>创建时间</th>
                <th>最后修改时间</th>
            </tr>
            </thead>
            <tbody id="Cglist">
            <%--展示分类名JS实现--%>
            </tbody>
        </table>
    </div>
</section>
<section class="page">
    <div class="container">
        <div id="fatie">
            <a href="../category/add"><button>新建</button></a>
        </div>


        <!-- <div id="pagefy">
            <ul>
                <form id="messageForm" action="#" method="post">
                    <input type="hidden" id="page" name="page" value="3">
                    <input type="hidden" id="last" name="last" value="1">
                    <li><a href="#" onclick="submitMessageForm('first')">首页</a></li>
                    <li><a href="#" onclick="submitMessageForm('pre')">上一页</a></li>
                    <li><a href="#">当前第1页</a></li>
                    <li><a href="#" onclick="submitMessageForm('next')">下一页</a></li>
                    <li><a href="#" onclick="submitMessageForm('last')">尾页</a></li>
                </form>
            </ul>
        </div> -->
    </div>
</section>
<footer>
</footer>
</body>
</html>
